// components/system/disease_encyclopedia/disease_encyclopedia.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        page: 1,
        total: 0,
        size: 5,
        isLoadedAll: false,
        fishBaiKeList: [],

        fishName: '',

        // 节流阀
        isLoading: false,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        detail(e){
            wx.navigateTo({
                url: `/pkgA/encyclopediaDetail/encyclopediaDetail?id=${e.currentTarget.dataset.id}&type=1`,
              })
        },

        // 组件上拉触顶加载下一页：
        //实现方法：由systems的onReachBottom()调用组件encyclopedia的onReachBottom(),然后encyclopedia调用组件fish_encyclopedia的fishBaiKeLoad()来实现子组件的上拉触顶效果
        diseaseLoad() {
            //如果数据都加载完
            if ((this.data.page - 1) * this.data.size >= this.data.total) {
                this.setData({
                    isLoadedAll: true
                })
                console.log("加载完了！！")
                return
            }

            // 节流阀
            if (!this.data.isLoading) {
                this.setData({
                    isLoading: true
                })

                wx.showLoading({
                    title: '加载中...',
                })

                wx.request({
                    url: `http://120.77.156.205:8808/wx/fishdiseases/getFishBaiKe/${this.data.page}/${this.data.size}
                `,
                    method: 'POST',
                    data: {

                    },
                    success: (res) => {
                        console.log(res.data)
                        if (res.data.code == 0) {
                            this.setData({
                                fishBaiKeList: [...this.data.fishBaiKeList, ...res.data.data.rows],
                                page: this.data.page + 1,
                                total: res.data.data.total
                            })
                            console.log(this.data.fishBaiKeList)
                        }
                    }
                })

                wx.hideLoading({
                    success: (res) => { },
                })

                //如果数据都加载完
                if ((this.data.page - 1) * this.data.size >= this.data.total) {
                    this.setData({
                        isLoadedAll: true
                    })
                }

            }
            this.setData({
                isLoading: false
            })
        },

        onChange(e) {
            this.setData({
                value: e.detail,
            });
            console.log("内容变化", this.data.value)
        },
        onSearch() {
            console.log("确定搜索", this.data.value)
        },
    },
    lifetimes: {
        //组件加载就加载第一页数据
        attached: function () {

            wx.request({
                url: `http://120.77.156.205:8808/wx/fishdiseases/getFishBaiKe/
                ${this.data.page}/${this.data.size}
              `,
                method: 'POST',
                data: {
                },
                success: (res) => {

                    console.log(res.data)
                    if (res.data.code == 0) {
                        this.setData({
                            fishBaiKeList: res.data.data.rows,
                            page: this.data.page + 1,
                            total: res.data.data.total
                        })
                        // console.log(this.data.fishBaiKeList)
                        if (this.data.total <= this.data.size) {
                            this.setData({
                                isLoadedAll: true
                            })
                        }
                    }
                }

            })


        },

    },

})
